package com.ctosb.classviewer.clazz.cp;

import com.ctosb.classviewer.ClassReader;
import com.ctosb.classviewer.clazz.ClassFile;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class CONSTANT_Methodref_info extends Cp_info {

    private short class_index;
    private short name_and_type_index;

    @Override
    protected void doParse(ClassReader classReader) {
        class_index = classReader.readShort();
        name_and_type_index = classReader.readShort();
    }

    /**
     * 获取class名称
     * @Author alan
     * @Date 2020/12/13 10:09 下午
     * @param classFile
     * @return
     */
    public String getClassName(ClassFile classFile) {
        CONSTANT_Utf8_info cp_info = (CONSTANT_Utf8_info)classFile.getConstant_pool()[class_index];
        return cp_info.getValue();
    }

    /**
     * 获取name值
     * @Author alan
     * @Date 2020/12/13 10:09 下午
     * @param classFile
     * @return
     */
    public String getNameValue(ClassFile classFile) {
        CONSTANT_NameAndType_info cp_info = (CONSTANT_NameAndType_info)classFile.getConstant_pool()[name_and_type_index];
        return cp_info.getNameValue(classFile);
    }

    /**
     * 获取descriptor值
     * @param classFile
     * @return
     */
    public String getDescriptorValue(ClassFile classFile) {
        CONSTANT_NameAndType_info cp_info = (CONSTANT_NameAndType_info)classFile.getConstant_pool()[name_and_type_index];
        return cp_info.getDescriptorValue(classFile);
    }

}
